package com.lineage.server.timecontroller.skill;

import com.lineage.server.model.Instance.L1EffectInstance;
import com.lineage.server.model.Instance.L1EffectType;
import com.lineage.server.thread.GeneralThreadPool;
import com.lineage.server.world.WorldEffect;
import java.util.Collection;
import java.util.Iterator;
import java.util.TimerTask;
import java.util.concurrent.ScheduledFuture;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class EffectCubeHarmonizeTimer extends TimerTask {
  private static final Log _log = LogFactory.getLog(EffectCubeHarmonizeTimer.class);
  
  private ScheduledFuture<?> _timer;
  
  public void start() {
    int timeMillis = 500;
    this._timer = GeneralThreadPool.get().scheduleAtFixedRate(this, 500L, 500L);
  }
  
  public void run() {
    try {
      Collection allNpc = WorldEffect.get().all();
      if (allNpc.isEmpty())
        return; 
      Iterator<L1EffectInstance> iter = allNpc.iterator();
      while (iter.hasNext()) {
        L1EffectInstance effect = iter.next();
        if (effect.effectType() == L1EffectType.isCubeHarmonize) {
          EffectCubeExecutor.get().cubeBurn(effect);
          Thread.sleep(1L);
        } 
      } 
    } catch (Exception e) {
      _log.error("Npc L1Effect幻术师技能(立方：和谐)状态送出时间轴异常重启", e);
      GeneralThreadPool.get().cancel(this._timer, false);
      EffectCubeHarmonizeTimer cubeHarmonizeTimer = new EffectCubeHarmonizeTimer();
      cubeHarmonizeTimer.start();
    } 
  }
}
